package open.tech.dawn.web.util;

import cn.hutool.crypto.digest.DigestUtil;

/**
 * MD5加密类（封装jdk自带的md5加密方法）
 */
public class MD5Util {

    public static String encrypt(String source, String salt) {
        return encrypt(source + salt, 5);
    }

    public static String encrypt(String source) {
        return encrypt(source, 5);
    }

    /**
     * @param source
     * @param count  加密次数
     * @return
     */
    private static String encrypt(String source, int count) {
        if (count <= 0) {
            return source;
        }
        String md5 = source;
        for (int i = 0; i < count; i++) {
            md5 = DigestUtil.md5Hex(md5);
        }
        return md5;
    }


}
